(function ($) {
    "use strict";

    $("#content").SearchPage({
        url: "/dbschedule/mq/getAllViewMQConfig",
        primaryKey: 'mqConfigId',
        batchBtns: [
            {translateFor: 'btn.batchDeleteMQConfig', action: 'batchDeleteMQConfig'}
        ],
        columns: [
            {label: 'label.mqConfigId', code: 'mqConfigId', minWidth: '9rem', textEllipsis: true, primary: true, selector: true, order: true},
            {label: 'label.mqType', code: 'mqType', minWidth: '7.5rem', align: 'center', selector: true, translateFor: 'mqType', filter: true},
            {label: 'label.mqTypeParams', minWidth: '10rem', selector: true, value: function (data) {
                if (data.mqType == 'R') {
                    return '<span class="mr-4"><span class="translate hint" translateFor="hint.mqNameServer"></span> ' + (data.mqConnection || '') + '</span>'
                        + '<span class="mr-4"><span class="translate hint"  translateFor="hint.mqProducerGroupName"></span> ' + (data.mqProducerGroupName || '') + '</span>'
                        + '<span class="mr-4"><span class="translate hint" translateFor="hint.mqConsumerGroupName"></span> ' + (data.mqConsumerGroupName || '') + '</span>';
                } else {
                    return '<span class="mr-4"><span class="translate hint" translateFor="hint.mqBrokerUrl"></span> ' + (data.mqConnection || '') + '</span>'
                        + '<span class="mr-4"><span class="translate hint" translateFor="hint.mqUser"></span> ' + (data.mqUser || '') + '</span>'
                        + '<span class="mr-4"><span class="translate hint" translateFor="hint.mqPassword"></span> ' + (data.mqPassword || '') + '</span>';
                }
            }},
            {type: 'action',  minWidth: '7rem', btns: [
                {translateFor: 'text.edit', action: 'editMQConfig', icon: 'la la-edit edit'},
                {translateFor: 'text.delete', action: 'deleteMQConfig', icon: 'la la-trash delete'}
            ]}
        ],
        editMQConfig: function (data) {
            newNormalModal({
                title: 'modal.title.editMQConfig',
                titleReplace: cdata(data.mqConfigId),
                showFooter: false,
                url: "/webjars/html/dbschedule/edit-mq-config.htm",
                executeJs: "/webjars/js/dbschedule/edit-mq-config.js",
                data: data.mqConfigId,
                modalId: 'editMQConfig',
                hideFun: () => this.refresh()
            });
        },
        deleteMQConfig: function (data, row) {
            newNormalModal({
                title: 'modal.title.editMQConfig',
                titleReplace: cdata(data.mqConfigId),
                showFooter: false,
                url: "/webjars/html/dbschedule/edit-mq-config.htm",
                executeJs: "/webjars/js/dbschedule/edit-mq-config.js",
                data: data.mqConfigId,
                modalId: 'editMQConfig',
                hideFun: () => this.refresh()
            });
        },
        batchDeleteMQConfig: function (data, row) {
            var id = data.mqConfigId;
            newNormalModal({
                title: 'modal.title.editMQConfig',
                titleReplace: cdata(id),
                showFooter: false,
                url: "/webjars/html/dbschedule/edit-mq-config.htm",
                executeJs: "/webjars/js/dbschedule/edit-mq-config.js",
                data: id,
                modalId: 'editMQConfig',
                hideFun: () => this.refresh()
            });
        }
    });

})(jQuery);